<!--教师周报已审核页面-->
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
		<title></title>
		<script src="../../script/mui.min.js"></script>
		<link href="../../css/mui.min.css" rel="stylesheet"/>
		<link rel="stylesheet" type="text/css" href="../../css/base.css"/>
		<link rel="stylesheet" type="text/css" href="../../css/CFNetPP_Base.css">
		<script type="text/javascript" src="../../script/echarts.min.js"></script>
		<script type="text/javascript" charset="utf-8">
			mui.init();
		</script>
		<style>
			.listDiv .base_dark_grey {
				color: #000000
			}
			.listDiv .base_grey {
				color: #333333
			}
			.listDiv .base_light_gray {
				color: #666666;
			}
			.listDiv .mui-table-view-cell:after {
				background-color: #EDEDED;
			}
		</style>
	</head>
	<body>
		<ul id="list_page" class="mui-table-view checkapply listDiv" ></ul>
		<div class="noSign" hidden="hidden" id="noData">
			<img src="../../image/icon_img.png" width="60%">
			<p class="font16 top_15 base_dark_grey" >
				暂无数据
			</p>
		</div>
		<div class="loadFailure" hidden="hidden" id="noNet">
			<img src="../../image/icon_img01.png" width="60%">
			<p class="" >
				数据加载失败
			</p>
			<p>
				请检查您的网络
			</p>
			<button type="button" class="mui-btn mui-btn-outlined" onclick="RefreshData()">
				重新加载
			</button>
		</div>
	</body>
	<script src="../../script/common.js"></script>
	<script src="../../script/jquery.min.js" type="text/javascript"></script>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script type="text/javascript" src="../../script/MD5.js"></script>
	<script type="text/javascript" src="../../script/requestTool.js"></script>
	<script type="text/javascript" src="../../script/base64.min.js"></script>
	<script type="text/javascript">
		var refreshCount = 0;
		//更新数据条数
		var dataArr = new Array();
		var page = 1;
		var row = 10;
		var review = 1;
		var school_id = '';
		var company_id = '';
		//未审核
		apiready = function() {
			//			setupPage();
			showProgress();
			loadNewData();
			setRefreshHeader();
			setPullUpRefresh();
			ReceiveNotifi();
		}
		function RefreshData() {
			$('#noNet').hide();
			showProgress();
			loadNewData();
		}

		function loadData() {
			var param = {
				//      jid: $api.getStorage('cfnetppuid'),
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjid'),
				page : page,
				rows : row,
				reviewstatus : review, //未审核状态的周报列表
				school_id : school_id,
 				company_id : company_id
			};
			cfnetppPOST(urlLswk, param, true, function(data, status) {
				//				 alert(JSON.stringify(data));
				
				api.refreshHeaderLoadDone();
				hideProgress();
				if (status == 'success') {
					if (data.status == 1) {
						var dataArray = data.json;
						var list = dataArray.lst;
						if (list != null && list.constructor == Array && list.length > 0) {
							$('#noData').hide();
							refreshCount = list.length;
							var listArr = new Array();
							var htmlString = new String();
							if (page == 1) {
								for (var i = 0; i < list.length; i++) {
									var weeklyData = list[i];
									var data = {
										weeklyid : weeklyData.weeklyid,
										//周报id
										weeklytime : weeklyData.weeklytime,
										//周报时间
										studentid : weeklyData.studentid,
										//学生Uid
										studentname : weeklyData.studentname,
										//学生姓名
										comments : weeklyData.comments,
										//老师评语
									};
									listArr.push(data);
									htmlString += htmlStringWithName(data, i);
								}
								dataArr = listArr;
								$('#list_page').html(htmlString);
							} else {
								var oldCount = dataArr.length;
								for (var i = 0; i < list.length; i++) {
									var index = oldCount + i;
									var weeklyData = list[i];
									var data = {
										weeklyid : weeklyData.weeklyid,
										//周报id
										weeklytime : weeklyData.weeklytime,
										//周报时间
										studentid : weeklyData.studentid,
										//学生Uid
										studentname : weeklyData.studentname,
										//学生姓名
										//下周计划
										comments : weeklyData.comments,
										//老师评语
									};
									listArr.push(data);
									htmlString += htmlStringWithName(data, index);
								}
								dataArr = dataArr.concat(listArr);
								$('#list_page').append(htmlString);
							}
							setupTapCellClick();
						} else {
							if (page == 1) {
								$('#noData').show();
								$('#list_page').html('');
							} else {
								api.toast({
									msg : '没有更多数据了',
									duration : 2000,
									location : 'bottom'
								});
							}
						}
					} else {
						$('#noData').show();
					}
				} else {
					$('#noNet').show();
				}
			});
		}

		function loadNewData() {
			page = 1;
			loadData();
			//停止刷新控件
		}

		function loadMoreData() {
			page++;
			loadData();
		}

		function htmlStringWithName(data, index) {
			var time = parseInt(data.weeklytime);
			var weeklytime = getLocalTime(time);
			var spanComment = CommentisNull(data.comments);
			if (spanComment == null) {
				spanComment = '无评语';
			} else {
				spanComment = notTen(Base64.decode(data.comments));
			}
			return '<li dataid="' + index + '" class="mui-table-view-cell mui-media train_list_cell_t">' + '<div class="mui-media-body">' + '<p class="font16 base_dark_grey">' + data.studentname + '</p>' + '<p class="mui-ellipsis font14 base_grey width73 top_5">' + spanComment + '</p>' + '<span class=" mui-pull-right font14 base_light_gray timepos">' + weeklytime + '</span>' +
			//			        '<span class="shenhebtn' + 1 + ' mui-pull-right">已审核</span>' +
			'</div>' + '</li>'
		}

		function ReceiveNotifi() {
			api.addEventListener({
				name : 'RefreshWeeklyReviewedNotifi'
			}, function(ret, err) {
				//				alert(JSON.stringify(ret.value));
				loadNewData();
				//				api.toast({
				//					msg : '已刷新',
				//					duration : 4000,
				//					location : 'top'
				//				});
			});
			api.addEventListener({
			    name: 'selectTrainClassNotifi'
			}, function(ret, err) {
			    var value = ret.value;
			    var classid = value.id;
			    company_id = '';
			    if (classid == 0) {
			    	school_id = '';
			    }else{
			    	school_id = classid;
			    }
			    loadNewData();
			});
			api.addEventListener({
			    name: 'selectTrainCompanyNotifi'
			}, function(ret, err) {
			    var value = ret.value;
			    var companyid = value.id;
			    school_id = '';
			    if (companyid == 0) {
			    	company_id = '';
			    }else{
			    	company_id = companyid;
			    }
			    loadNewData();
			});
		}

		//		function getLocalTime(x) {
		//			var now = new Date(parseInt(x) * 1000);
		//			var year = now.getFullYear();
		//			var month = now.getMonth() + 1;
		//			var date = now.getDate();
		//			return year + "-" + month + "-" + date;
		//		}
		//获取点击条目
		function setupTapCellClick() {
			$('.train_list_cell_t').unbind('click');
			$('.train_list_cell_t').click(function() {
				var dataid = $(this).attr('dataid');
				var data = dataArr[parseInt(dataid)];
				var weeklyid = parseInt(data.weeklyid);
				//				var b = data.name;
				//				//				alert(b);
				api.openWin({useWKWebView:true,
					name : 'Teacher_WeeklyReviewedFrameDetail',
					url : 'Teacher_WeeklyReviewedFrameDetail.html',
					pageParam : {
						weeklyid : weeklyid,
						sourceurl : api.pageParam.sourceurl,
					    sourcetitle : api.pageParam.sourcetitle
					},
					allowEdit : true
				});
			});
		}

		//		function showProgress() {
		//			api.showProgress({
		//				style : 'default',
		//				animationType : 'fade',
		//				title : '努力加载中...',
		//				text : '先喝杯茶...',
		//				modal : false
		//			});
		//		}
		//		function hideProgress() {
		//			api.hideProgress();
		//		}
		//
		//		//下拉刷新
		//		function setRefreshHeader() {
		//			api.setRefreshHeaderInfo({
		//				visible : true,
		//				bgColor : '#ccc',
		//				textColor : '#fff',
		//				textDown : '下拉刷新...',
		//				textUp : '松开刷新...',
		//				showTime : true
		//			}, function(ret, err) {
		//				loadNewData();
		//			});
		//		}
		//
		//		// 上拉加载
		//		function setPullUpRefresh() {
		//			api.addEventListener({
		//				name : 'scrolltobottom'
		//			}, function(ret, err) {
		//				if (refreshCount >= row) {
		//					loadMoreData();
		//				}
		//			});
		//		}
	</script>
</html>